package process;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionRedirect;
import org.apache.struts.action.DynaActionForm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import dao_manager.ClientInfoManager;
import dao_manager.ClientInfoManagerImpl;
import beans.Commentaire;

public class ProcessCommentModif extends Action{
    
    Logger l = LoggerFactory.getLogger( ProcessCommentModif.class );
    private static final String ATT_CLIENT_INFO_ID ="Client_info_id";
	
	public ProcessCommentModif()
	{
		super ();
	}

	public ActionForward execute(
	        ActionMapping mapping,
	        ActionForm form,
	        HttpServletRequest request,
	        HttpServletResponse response)
	        throws Exception {

	    DynaActionForm daf = (DynaActionForm)form;
        String commentText = (String)daf.get( "commentaire");
        Long client_id=(Long) request.getSession().getAttribute( ATT_CLIENT_INFO_ID );	  
        
        l.debug(" ************************************** process comment Modification " + client_id + commentText);
        
        
        Commentaire commentaire=new Commentaire( commentText, request );
        ClientInfoManager clientInfoManager=new ClientInfoManagerImpl();
        clientInfoManager.saveCommentaire( commentaire, client_id );
        
 
        
        
        
	    ActionRedirect redirect = new ActionRedirect(mapping.findForward("success"));
	    redirect.addParameter(ATT_CLIENT_INFO_ID, client_id);
	    return redirect;
	    }

}
